package api

import (
	"fmt"
	"strings"
	"template/generation/generation"

	"github.com/spf13/cobra"
)

var (
	confirm   string
	yes       bool
	DeleteCmd = &cobra.Command{
		Use:     "clean",
		Short:   "清理当前项目目录配置文件(默认输入: configctl clean 直接清理当前目录)",
		Example: "configctl clean",
		Run: func(cmd *cobra.Command, args []string) {
			if yes, _ := cmd.Flags().GetBool("yes"); yes { //如果是: configctl clean -y 直接清理当前目录
				ad := generation.AutoCodeService{}
				str, err := ad.CleanPackageTemp()
				if err != nil {
					panic(err)
				}
				fmt.Println(str)

			} else { //如果是: configctl clean 没有加 ,则需要确认是否清理当前目录
				fmt.Print("Are you sure you want to delete? (Y/n): ")
				fmt.Scanln(&confirm)
				if strings.ToLower(confirm) == "y" {
					ad := generation.AutoCodeService{}
					str, err := ad.CleanPackageTemp()
					if err != nil {
						panic(err)
					}
					fmt.Println(str)
				} else {
					fmt.Println("Deletion cancelled.")
				}
			}

		},
	}
)

func init() {
	DeleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt and delete files")
}
